package shayu.order.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class MyMQConfig {

    // @Bean Binding queue exchange


    // 死信队列
    @Bean
    public Queue orderDelayQueue(){
        HashMap<String, Object> argumemts = new HashMap<>();
        /**
         *  Queue(String name ) 队列名字
         *  boolean durable 是否持久化
         *  boolean exclusive 是否排他
         *  boolean autoDelte 是否自动删除
         *  Map<String,Object> arguments> 属性
         */
        argumemts.put("x-dead-letter-exchange","order-event-exchange");
        argumemts.put("x-dead-letter-routing-key","order.release.order");
        argumemts.put("x-message-tt10",60000);

        Queue queue = new Queue("order.delay.queue", true, false, false, argumemts);

        return queue;
    }

    // 普通队列
    @Bean
    public Queue orderReleaseOrderQueue(){
        Queue queue = new Queue("order.release.order.queue", true, false, false);
        return queue;
    }

    @Bean
    public Exchange orderEventExchange(){

        return new TopicExchange("order-event-exchange",true,false);
    }

    @Bean
    public Binding orderCreateaOrderBuding(){
        /**
         *  String destination 目的地
         */
        return new Binding("order.delay.queue",Binding.DestinationType.QUEUE,
                "order-event-exchange",
                "order.create.order",
                null);
    }

    @Bean
    public Binding orderReleaseBinding(){
        return new Binding("order.release.order.queue",Binding.DestinationType.QUEUE,
                "order-event-exchange",
                "order.release.other.#",
                null);
    }

    // 订单释放直接和库存释放进行绑定
    @Bean
    public Binding orderReleaseOtherBinding(){
        return new Binding("stock.release.stock.queue",
                Binding.DestinationType.QUEUE,
                "order-event-exchange",
                "order.release.other.#",
                null);
    }

    @Bean
    public Queue QueueSeckillOrderQueue(){
        return new Queue("order.seckill.order.queue",true,false,false);
    }

    @Bean
    public Binding orderSeckillOrderQueueBinding(){
        return new Binding("order.seckill.order.queue",
                Binding.DestinationType.QUEUE,
                "order-event-exchange",
                "order.seckill.order",
                null);
    }


}
